﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using octopus_project.enumeration;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace octopus_project.tileset.mapCells {
    class Castle_MapCell : MapCell {

        public Castle_MapCell() {
            tileType = TileType.PLAYER_CASTLE;
            castle = true;
            StrongCell = new StrongCell(15);
        }

        public override void paint(SpriteBatch spriteBatch, int x, int y, TileMap_GameplayEntry map) {
            base.paint(spriteBatch, x, y, map);

            PlayersColor playerColor = PlayersColor.UNDEFINED;
            if (player != null) {
                playerColor = player.Color;
            }

            TileType tile = TileType.PLAYER_CASTLE;
            bool existLeft = false;
            bool existUp = false;

            MapCell mapCell = map.getMapCell(x - 1, y);
            if (x > 0) {
                
                if (mapCell.tileType == TileType.PLAYER_CASTLE) {
                    existLeft = true;
                }
                
            }
            if (y > 0) {
                mapCell = map.getMapCell(x, y - 1);
                if (mapCell.tileType == TileType.PLAYER_CASTLE) {
                    existUp = true;
                }
            }
            if (existLeft && !existUp) {
                tile = TileType.PLAYER_CASTLE_R_UP;
            }
            else if (!existLeft && existUp) {
                tile = TileType.PLAYER_CASTLE_L_DWN; 
            }
            else if (existLeft && existUp) {
                tile = TileType.PLAYER_CASTLE_R_DWN; 

            }

            spriteBatch.Draw(
                TileTypeExtensions.SpriteImage,
                new Rectangle(x * Constant.TILE_SIDE, y * Constant.TILE_SIDE, Constant.TILE_SIDE, Constant.TILE_SIDE),
                TileTypeExtensions.GetSourceRectangle(tile, playerColor),
                Color.White);



        }
        public override MapCell change(TileType tileTypeParam) {
            return this;
        }


    }
}
